package com.maple.hibernate;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

public class HibernateUtil2 {

	public static SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory() ;
	public static Map<Thread, Session> sessionMap=new HashMap<Thread, Session>(); 

	public  static Session openSession()
	{
		Session session=sessionFactory.openSession();
		sessionMap.put(Thread.currentThread(), session);
		return session;
	}
	
	public  static Session getCurrentSession()
	{
		return sessionMap.get(Thread.currentThread());
	}
	
	public static void closeAndRemoveCurrentSession()
	{
		Session session=sessionMap.get(Thread.currentThread());
		session.close();
		sessionMap.remove(Thread.currentThread());
	}

	


}
